<template>
  <div class="flex flex-col h-full">
    <SearchContainer @reset="() => formRef.resetFields()" @search="getData()">
      <a-form ref="formRef" class="flex-1" :model="formState" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="bm" class="w-1/5">
          <a-input v-model:value="formState.bm" placeholder="耗材名称" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="flex mb-3">
        <CompressExport name="医用耗材" code="1306" :search-params="formState" btn-name="下载导入" />
        <!-- <UploadTxt :upload-url="'/api/v1/insure/downloadYYHCTXT'" class="mr-2" @success="getData">导入TXT</UploadTxt> -->
        <BaseExportTxt name="医用耗材" code="000232" :search-params="formState" btn-name="导出" class="ml-2" />
      </div>
      <BaseTable
        column-code="000232"
        fill
        :scroll="{ x: 9500 }"
        :data-source="tableData"
        bordered
        :pagination="{ total: page.total, current: page.current, pageSize: page.pageSize }"
        @change="onPageChange"
      >
        <template #bodyCell="{ column, index }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
// import { message } from 'ant-design-vue'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'
import { post } from '@/utils/request'
// import UploadTxt from '../components/UploadTxt'
import BaseExportTxt from '../components/BaseExport'
import CompressExport from '../components/CompressExport'

const loading = ref(false)
const formRef = ref(null)
const page = ref({ total: 0, current: 1, pageSize: getSystemConfig('DFFAULT_PAGE_SHOW_COUNT') || 10 })
const formState = ref({ bm: '' })
const tableData = ref([])

const getData = async () => {
  loading.value = true
  const { code, data, total } = await post('/insure/selectYYHCList', {
    pageNum: page.value.current,
    pageSize: page.value.pageSize,
    ...formState.value
  })
  loading.value = false
  if (code === 0) {
    page.value.total = total
    tableData.value = data.map((item) => {
      item.yxzt = item.yxzt ? '1' : '0'
      return item
    })
  }
}

const onPageChange = ({ current, pageSize }) => {
  page.value.current = current
  page.value.pageSize = pageSize
  getData()
}
onMounted(() => {
  getData()
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
